package com.kuaifawu.lwnlawyerclient.Adapter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.kuaifawu.lwnlawyerclient.Activity.LWNQuestionDetailActivity;
import com.kuaifawu.lwnlawyerclient.Activity.LWNReportActivity;
import com.kuaifawu.lwnlawyerclient.R;

import java.util.List;

/**
 * Created by wyk123 on 2015/7/6.
 */
public class LWNAdapter_reportList extends BaseAdapter {
    private LayoutInflater mInflater;
    private Activity context_this;
    private Intent intent=null;
    private Bundle bundle=null;
    private List<String> list;
    private String questionId="";

    public LWNAdapter_reportList(Activity context, List<String> list,String questionId){
        this.mInflater = LayoutInflater.from(context);
        context_this = context;
        this.questionId=questionId;
        this.list = list;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder mHolder=null;


        if(convertView==null){
            mHolder=new ViewHolder();
                    convertView = mInflater.inflate(R.layout.item_report, parent, false);
            mHolder.itemdata=(TextView)convertView.findViewById(R.id.itemdata);
            convertView.setTag(mHolder);
        }else{
            mHolder=(ViewHolder)convertView.getTag();
        }

        mHolder.itemdata.setText(list.get(position));

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (position){
                    case 0:
                        LWNReportActivity.saveReport(list.get(position),questionId,context_this);
                        //context_this.startActivity(intent)


                        break;
                    case 1:
                        LWNReportActivity.saveReport(list.get(position),questionId,context_this);

                        break;
                    case 2:
                        LWNReportActivity.saveReport(list.get(position),questionId,context_this);


                        break;
                    case 3:

                        LWNReportActivity.saveReport(list.get(position),questionId,context_this);

                        break;

                    case 4:

                        Intent intent=new Intent();
                        intent.setClass(context_this,LWNReportActivity.class);
                        Bundle bundle=new Bundle();
                        bundle.putString("questionId",questionId);
                        intent.putExtras(bundle);
                        context_this.startActivity(intent);
                        if( LWNQuestionDetailActivity.reportpopupWindow.isShowing()){
                            LWNQuestionDetailActivity.reportpopupWindow.dismiss();
                        }

                        break;

                }
            }

        });

        return convertView;
    }

    class ViewHolder{
        private TextView itemdata;
    }
}
